package com.junzhiit.nengji.shop.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.shop.dao.GoodsTagDAO;
import com.junzhiit.nengji.shop.model.GoodsTag;

@Repository
public class GoodsTagDAOImpl extends AbstractBaseDAO<GoodsTag> implements GoodsTagDAO{
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	@Override
	public boolean deleteByGoodsId(String goodsId){
		StringBuffer sql=new StringBuffer();
		sql.append(" delete from goods_tag ");
		sql.append(" where goods_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(goodsId);
		
		return updateForBoolean(sql.toString(), param);
	}
	
	@Override
	public List<String> getAllByGoodsId(String goodsId){
		StringBuffer sql=new StringBuffer();
		sql.append(" select tag_id from goods_tag");
		sql.append(" where goods_id=?");
		
		StatementParameter param=new StatementParameter();
		param.setString(goodsId);
		
		return queryForStrings(sql.toString(),param);
	} 
}
